package com.ruoyi.project.system.domain;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.ruoyi.framework.aspectj.lang.annotation.Excel;
import com.ruoyi.framework.web.domain.BaseEntity;
import lombok.Data;
import lombok.experimental.Accessors;
import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

/**
 * 用户信息对象 sys_user
 */
@Data
@Accessors(chain = true)
public class SysUser extends BaseEntity {

    private static final long serialVersionUID = 1L;

    /**
     * 用户ID
     */
    private Long userId;

    /**
     * 用户账号
     */
    @Excel(name = "用户账号")
    private String userName;

    /**
     * 用户昵称
     */
    @Excel(name = "用户昵称")
    private String nickName;

    /**
     * 密码
     */
    private String password;

    /**
     * 帐号状态（0正常；1停用）
     */
    @Excel(name = "帐号状态", readConverterExp = "0=正常；1停用")
    private String status;

    /**
     * 删除标志（0存在；1删除）
     */
    private String delFlag;

    /**
     * 最后登录IP
     */
    @Excel(name = "最后登录IP")
    private String loginIp;

    /**
     * 最后登录时间
     */
    @JsonFormat(pattern = "yyyy-MM-dd")
    @Excel(name = "最后登录时间", width = 30, dateFormat = "yyyy-MM-dd")
    private Date loginDate;

    /**
     * 角色ID
     */
    @Excel(name = "角色ID")
    private Integer roleId;

    /**
     * 上级用户ID
     */
    @Excel(name = "上级用户ID")
    private Long parentId;

    /**
     * 邀请用户ID
     */
    @Excel(name = "邀请用户ID")
    private Long inviteId;

    @Excel(name = "转账姓名")
    private String alipayName;

    @Excel(name = "转账账号")
    private String alipayAccount;

    @Excel(name = "启用秒到账（0不启用；2启用）")
    private String enableTansferAccounts;

    @Excel(name = "单次提现最大免批额")
    private BigDecimal maxTansferAccounts;

    /**
     * 角色对象
     */
    private List<SysRole> roles;

    public SysUser() {
    }

    public SysUser(Long userId, Integer roleId, Long parentId) {
        this.userId = userId;
        this.roleId = roleId;
        this.parentId = parentId;
    }

    public SysUser(Long userId, String alipayName, String alipayAccount) {
        this.userId = userId;
        this.alipayName = alipayName;
        this.alipayAccount = alipayAccount;
    }

    public SysUser(Long userId, String userName, String nickName, Integer roleId, String remark) {
        this.userId = userId;
        this.userName = userName;
        this.nickName = nickName;
        this.roleId = roleId;
        this.setRemark(remark);
    }

    public boolean isAdmin() {
        return isAdmin(this.roleId);
    }

    public static boolean isAdmin(Integer roleId) {
        return roleId != null && 1L == roleId;
    }

}
